<template>
  <div class="bar">
    <el-col :span="24">
      <h5>自定义颜色</h5>
      <el-menu
        default-active="2"
        class="el-menu-vertical-demo"
        @open="handleOpen"
        @close="handleClose"
        background-color="rgb(48, 65, 86)"
        text-color="#fff"
        active-text-color="#ffd04b"
      >
        <div v-for="(menu,index) in menusList" :key="index">
          <div v-if="!menu.hidden">
            <el-submenu v-if="menu.child && menu.child.length > 0" :index="(index+1).toString()">
              <template slot="title">
                <i :class="menu.icon"></i>
                <span>{{menu.name}}</span>
              </template>
              <el-menu-item-group>
                <div v-for="(cmenu,id) in menu.child" :key="id">
                  <!-- <i :class="cmenu.icon"></i> -->
                  <el-menu-item index="1-1" v-on:click="change(cmenu.url)">{{cmenu.name}}</el-menu-item>
                </div>
              </el-menu-item-group>
            </el-submenu>

            <el-menu-item v-else :index="(index+1).toString()" @click="change(menu.url)">
              <template slot="title">
                <i :class="menu.icon"></i>
                <span>{{menu.name}}</span>
              </template>
            </el-menu-item>
          </div>
        </div>
      </el-menu>
    </el-col>
  </div>
</template>


<script>
export default {
  data() {
    return {
      menusList: []
    };
  },
  created() {
    this.getMenuList();
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    change(menu) {
      this.$router.push(menu);
    },
    getMenuList() {
      console.log(this.$router.options.routes)
      this.menusList = this.$router.options.routes[2].children;
    }
  }
};
</script>

<style>
.bar {
  position: relative;
  width: 100%;
  height: 100%;
}
</style>